Repository navigation
shell(rm): stop panicking on operands longer than the path scratch buffers - #37521
Conversation
…ffers The preserve-root check joined every relative operand onto the cwd through the 4096-byte thread-local join buffer and then normalized the result into the 1024-byte thread-local normalize buffer, neither of which is bounds checked, so any operand longer than either aborted the process with "range end index N out of range for slice of length 1024" before rm looked at the filesystem. Join through join_spill and normalize into a Vec sized to the input so the check runs for operands of any length; the unlink then fails with ENAMETOOLONG like any other bad operand.
|
Warning Review limit reached
Next review available in: 12 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Comment |
|
Updated 8:27 AM PT - Aug 11th, 2026
❌ @robobun, your commit 5977a80 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 37521That installs a local version of the PR into your bun-37521 --bun |
|
Status
|
There was a problem hiding this comment.
LGTM — mechanical buffer swap that turns a user-reachable panic into the expected per-operand error.
What was reviewed:
join→join_spillandnormalize_string→normalize_string_bufare the same underlying implementations with the same const generics (<false, Auto, false>matches whatnormalize_string::<false, Auto>expands to); only the destination buffer changes.normalize_bufsizing atresolved.len() + 1checked againstnormalize_string_generic_tz: POSIX never grows the output; Windows can grow by exactly one byte (bareC:→C:., UNC volume-only), so the +1 is sufficient.- No aliasing between the two loop-reused
Vecs and the thread-localJOIN_BUFthatjoin_spillmay still return a slice into. - Test covers both scratch-buffer thresholds, mixed operands (proves the non-failing operand is still processed), and the long
../chain (proves the root check still fires); child-process isolation,Buffer.allocover.repeat, concurrent pipe drain per harness conventions.
Extended reasoning...
Overview
The PR fixes a panic in src/runtime/shell/builtin/rm.rs's preserve-root check. Before scheduling any work, rm joins each operand with the shell cwd and normalizes the result to see if it resolves to /. Both resolve_path::join and resolve_path::normalize_string write into fixed-size thread-local scratch buffers (JOIN_BUF = 4096 B, PARSER_BUFFER = 1024 B) with plain slice indexing, so an operand longer than either aborts the whole process. The fix swaps to join_spill (existing helper that falls back to a caller Vec) and normalize_string_buf (caller-provided buffer), reusing two Vecs across the operand loop. A new test in test/js/bun/shell/commands/rm.test.ts exercises operands past both thresholds, an absolute variant, a mixed invocation, and a long ../ chain.
Security risks
None introduced. The change removes a user-triggerable abort (a DoS on any script that shells out rm on untrusted paths). The preserve-root guard's semantics are unchanged — verified that join_spill dispatches to the same join_string_buf as join, and that normalize_string::<false, Auto> is exactly normalize_string_buf::<false, Auto, false> on PARSER_BUFFER — so no new bypass. The upToRoot test case demonstrates the guard still refuses a long ../ chain that collapses to /.
Level of scrutiny
Low-to-moderate. The diff is ~15 lines of Rust that swaps buffer plumbing without touching control flow, error paths, or the surrounding unsafe DirTask machinery. I traced normalize_string_generic_tz to confirm the resolved.len() + 1 sizing: with ALLOW_ABOVE_ROOT=false, PRESERVE_TRAILING_SLASH=false, ZERO_TERMINATE=false, ADD_NT_PREFIX=false, POSIX output never exceeds input length, and Windows grows by at most one byte (bare drive letter C:→C:., or UNC volume-only trailing separator). The two Vecs are separate allocations from each other and from any thread-local join_spill may return a slice into, so there is no read/write aliasing.
Other factors
The test follows repo conventions closely: child process so the pre-fix crash surfaces as an assertion rather than killing the runner, Buffer.alloc(n, fill).toString() instead of .repeat(), {...bunEnv} spread, concurrent Promise.all pipe drain, stderr asserted before exit code, and isWindows gating where errno text and the root check differ. The PR description notes that mv/mkdir/touch share the same pattern and are tracked separately, which is a reasonable scope boundary since those use different join/normalize call sites. No prior human review comments; no CODEOWNERS entry for src/runtime/shell/.
…024 bytes (#37526) ## Reproduction Any package.json the resolver reads (a dependency in `node_modules`, or the project's own) whose `"browser"` object has a key longer than 1024 bytes: ```sh mkdir -p node_modules/x && cd node_modules/x bun -e 'require("fs").writeFileSync("package.json", JSON.stringify({ name: "x", main: "index.js", browser: { ["./" + "b".repeat(1100) + ".js"]: "./y.js" } }))' echo 'module.exports = 1;' > index.js && cd ../.. echo 'console.log(require("x"))' > index.js bun index.js ``` ``` panic: range end index 1103 out of range for slice of length 1024 ``` The process aborts (exit 134) as soon as the package.json is parsed, so it happens at runtime too, not only for `--target=browser` (the browser map is read regardless of target because parsed package.json files are cached). Expected: prints `1`; the mapping is just an entry that nothing matches. ## Cause `PackageJSON::parse` (`src/resolver/package_json.rs`) normalizes every browser map key with `resolve_path::normalize_string`, which writes its output into the thread-local `PARSER_BUFFER`, a fixed `[u8; 1024]` (`src/paths/resolve_path.rs`), with no bounds check. Keys are arbitrary strings from the package.json, so any key whose normalized form is longer than the buffer aborts. The parse side had this limit since the Zig version (same 1024-byte `parser_buffer`). ## Fix Add `resolve_path::normalize_string_spill`, the `normalize_string` counterpart of the existing `join_spill` / `join_z_spill`: it uses the thread-local buffer when the result is known to fit and otherwise normalizes into a caller-owned `Vec` that is grown as needed (untouched in the common case, so the fast path allocates nothing). The browser map loop uses it with one `Vec` hoisted out of the loop, the same shape as the `join_spill` callers in `fs.readdir` and `Bun.Glob`. `StringArrayHashMap::put` already copies the key, so the intermediate `Box<[u8]>` the old shim allocated per entry is gone as well. The capacity check is `input.len() + 1`: normalizing only removes bytes, except that on Windows a drive-relative `C:` normalizes to `C:.` and a bare UNC volume gains its trailing separator, both one byte longer than the input. The unit test below pins the boundary case (a UNC volume exactly 1024 bytes long); dropping the `+ 1` makes it fail with the same out-of-range panic. The remaining `normalize_string` callers (`FileSystem::normalize` used by the install folder resolver, the shell `rm` check being fixed in #37521, and a Windows-only path in `run_command.rs`) are separate call sites and can move to the new helper independently; the `sideEffects` entries a few lines below the browser map go through the 4096-byte join buffer instead and are tracked separately too. ## Verification `test/js/bun/resolve/resolve.test.ts`, next to the existing browser-map long-path test: a dependency with an over-long key is required at runtime, a browser build with an over-long key still applies the other entries of the map, and (Linux/Windows, where PATH_MAX allows the lookup) a bare specifier of that length is actually remapped through the over-long key. ``` USE_SYSTEM_BUN=1 bun test test/js/bun/resolve/resolve.test.ts -t "browser map with a key longer" 3 fail (each child aborts with the panic above) bun bd test test/js/bun/resolve/resolve.test.ts 76 pass, 2 skip bun bd test test/bundler/bundler_browser.test.ts test/bundler/esbuild/packagejson.test.ts all pass (browser map behavior for normal keys is unchanged) cargo test -p bun_paths 18 pass (4 new, covering the fast path, the spill, spill reuse, and the +1 boundary) bun run rust:miri -p bun_paths 18 pass ``` The new unit tests are the first in `bun_paths` to reach `bun_core::strings`' byte searches, so the test module defines scalar stubs for the two highway kernels they reference, the same way `string_paths.rs` stubs simdutf; under Miri the wrappers take their own scalar path and the stubs are never called.
…tead of aborting (#38379) ### Problem - `Bun.$` `mkdir <operand>` with a relative operand longer than the join buffer, and `touch <operand>` with any operand longer than a path buffer, abort the process: `panic: range end index 5004 out of range for slice of length 4094` (cwd `/tmp`, 5000-byte operand; same for `mkdir -p` and for an absolute `touch` operand). - `mkdir` with an absolute operand that does not fit a path buffer reports the wrong error: `mkdir: /aaa...: No such file or directory` instead of `File name too long`. - Cause, crash: `ShellMkdirTask::run_from_thread_pool` (`src/runtime/shell/builtin/mkdir.rs`) joins a relative operand onto the cwd with `resolve_path::join_z`, which writes into a fixed 4096-byte thread-local buffer; `ShellTouchTask::run_from_thread_pool` (`touch.rs`) joins both kinds of operand with `join_z_buf` into a stack `PathBuffer`. Neither join bounds-checks its output (`normalize_string_generic_tz` in `src/paths/resolve_path.rs`), and the operand comes straight from the user. - Cause, wrong error: mkdir hands the joined path to the node:fs mkdir implementation as a `PathLike`. For JS callers, `Valid::path_string_length` (`src/runtime/node/types.rs`) rejects paths of `MAX_PATH_BYTES` or more up front; for anything longer, `PathLike::slice_z` returns `""` and `mkdir("")` fails with ENOENT. The shell builds the `PathLike` itself and skipped that check. ### Fix - Both builtins join through `join_z_spill`, the existing variant that falls back to a caller-owned `Vec` when the parts would not fit (the same helper `fs.readdir`, `Bun.Glob` and the open `rm` fix #37521 use). The result is the same normalized path as before for every operand that used to work. - `mkdir` then reports `ENAMETOOLONG` itself, naming the path, when the path it is about to create is `MAX_PATH_BYTES` or longer, i.e. the bound node:fs assumes. For a relative operand that is the joined, normalized path, so a long `././.../x` spelling is still created; an absolute operand is passed on as written (as before: normalizing it would change what `..` means across a symlink), so it is bounded as written, which is also what the kernel and coreutils do with such an operand. Both cases are in the test. - `touch` needs no check of its own: it calls `bun_sys::utimens` / `open` with the string as is, and the OS reports `ENAMETOOLONG` for it like for any other operand. It also no longer puts a `PathBuffer` on the worker's stack (about 96 KB on Windows). - Verified with `test/js/bun/shell/commands/mkdir.test.ts` and `touch.test.ts` (the `commands/` directory has one file per builtin; these two had none). Each runs the builtin in a child bun and covers a 5000-byte relative and absolute operand, `mkdir -p`, a 100000-byte operand (longer than the buffer on Windows too), a long operand next to a normal one that must still be created, and a 6000-byte `./` spelling that must still succeed (for mkdir also the absolute form of it, which must be refused as written; POSIX only, since on Windows it fits the buffer). - `USE_SYSTEM_BUN=1 bun test test/js/bun/shell/commands/mkdir.test.ts test/js/bun/shell/commands/touch.test.ts`: both fail, the child aborts with the panic above. Without the new mkdir check, the mkdir cases fail on the ENOENT message instead. - `bun bd test test/js/bun/shell/commands/mkdir.test.ts test/js/bun/shell/commands/touch.test.ts`: pass. `bunshell.test.ts`, `file-io.test.ts`, `commands/rm.test.ts` pass as well; `cargo check` for the Windows and macOS targets is clean. - Windows: the released build aborts on the 5000-byte relative `mkdir` operand there too (the join buffer is 4096 bytes on every platform), and creates the directory for the absolute `././.../x` spelling (the branch this change does not touch below 98302 bytes), which is what the Windows side of the test asserts; both checked on a Windows x64 machine. The Windows lanes of this PR's CI runs pass both test files. - Related open PRs: `rm` (#37521), `mv` (#37527) and `cp` (#38162) fix the same pattern in their builtins; #38162 adds `shell_join_path` helpers in `interpreter.rs` that touch could switch to in one line once either PR lands. #38002 (empty operands) also creates `commands/mkdir.test.ts` and `touch.test.ts`; whichever lands second appends its test to the other's file. `ls -R` joins real directory entries through the same thread-local buffer, but that needs an on-disk tree within PATH_MAX whose entries join past 4096 bytes rather than a long operand, and is left alone here. ### Background - Shell builtins run in-process; `mkdir` and `touch` schedule one task per operand on the worker pool. A task either succeeds or stores a `bun_sys::Error`, which the builtin prints as `<cmd>: <path>: <coreutils message>` and turns into exit code 1 once every task has finished, so one failing operand does not stop the others. - The shell has its own cwd (`$.cwd()`, `cd`), which can differ from the process cwd, so these builtins make relative operands absolute by joining them onto the shell cwd as strings before calling an implementation that takes a path. - `resolve_path::join_z` and `join_z_buf` concatenate and normalize their parts (`.`, `..`, repeated separators) into a fixed buffer without checking that the result fits; the `*_spill` variants take a `Vec` to grow into when the unnormalized length would not fit, and otherwise behave identically. - `PathBuffer` is `[u8; MAX_PATH_BYTES]`: 4096 bytes on Linux, 1024 on macOS, 98302 on Windows. The node:fs layer copies every path it receives into one, which is why its JS entry points reject longer paths before calling it. <!-- robobun:evidence:begin --> --- **no test proof** · iteration 0 · Platform-specific test(s) that do not run on this machine. Deferring to CI, which covers all platforms: test/js/bun/shell/commands/mkdir.test.ts test/js/bun/shell/commands/touch.test.ts <!-- robobun:evidence:end -->
…an PATH_MAX (#39578) ### Problem - `Bun.$` `rm -rf <dir>` aborts the whole process when the tree under `<dir>` has an entry whose path is longer than the path buffer: `panic: range end index 4160 out of range for slice of length 4094` (exit 134). With an absolute operand the message reads `... out of range for slice of length 4095`. - The panic happens on a thread pool thread. No JS code can catch it, and `.nothrow()` does not help. - Cause, files: `ShellRmTask::buf_join` (`src/runtime/shell/builtin/rm.rs`) joins the directory path and the entry name with `join_z_buf` into a stack `PathBuffer`. The join writes the result with plain slice indexing, so a result longer than the buffer panics. - Cause, directories: `ShellRmTask::join` does the same for an absolute operand with `resolve_path::join`, which writes into a 4096 byte thread-local buffer. (For a relative operand this branch already builds a `Vec`.) - A directory path that still fits the buffer can hold an entry that does not. The walk reaches such an entry on every tree deeper than `PATH_MAX`. Such trees are legal. `mkdir` relative to an open directory creates them, and so do `tar` and `git`. ### Fix - `buf_join` joins through `join_z_buf_spill`. It uses the `PathBuffer` as before when the result fits, and a `Vec` owned by the readdir loop when it does not. - The absolute branch of `join` uses `join_spill` the same way. - The result for every path that used to work is unchanged. A path that does not fit now reaches `unlinkat` or `openat` whole, and the OS rejects it with `ENAMETOOLONG`. `rm` reports that as `rm: <path>: File name too long` and exits 1, like every other failed entry. - `join_z_buf_spill` and `join_spill` are the existing helpers that `fs.readdir`, `Bun.Glob` and `fs.watch` use for the same problem. #37521 (the preserve-root check in `rm`) and #38379 (`mkdir`, `touch`) use them for the other shell sites. - Test: `test/js/bun/shell/commands/rm.test.ts`, "recursive rm reports an entry deeper than PATH_MAX instead of crashing". It builds two trees whose deepest directory is `PATH_MAX - 64` bytes long (`PATH_MAX` is 4096 on Linux and 1024 on the other POSIX platforms, the same split as `MAX_PATH_BYTES`), one with a 100 byte file and one with a 100 byte directory inside, so both joins are exercised. It runs `rm -rf` on each in a child process and expects exit 1 and the `File name too long` line for the entry, then a normal `rm -rf` that still succeeds. Skipped on Windows, where the path limit is different. - `USE_SYSTEM_BUN=1 bun test test/js/bun/shell/commands/rm.test.ts -t "deeper than PATH_MAX"`: fails with the panic above. - `bun bd test test/js/bun/shell/commands/rm.test.ts`: 8 pass. - `cargo fmt --all -- --check`: clean. ### Background `rm -r` in the Bun shell is a tree of `DirTask`s. The root task holds the operand as written. When a task reads a directory, it removes each file entry itself and creates a child task for each directory entry. Every task stores the full path of its entry, relative to the shell cwd when the operand was relative, and passes that path to `unlinkat`, `openat` or `rmdirat` with the shell cwd fd. The two joins in this PR are where those full paths are built. `PATH_MAX` (4096 on Linux) bounds one path string that the kernel accepts in a syscall. It does not bound how deep a tree can be, because a process can always create an entry relative to an open directory. So a walker that builds full paths has to expect paths longer than its buffers. The OS then rejects the syscall with `ENAMETOOLONG`, which is the error coreutils also shows for such an entry when it cannot use `*at` calls. `resolve_path::join_z_buf` and `resolve_path::join` normalize the joined parts (collapse `//`, resolve `.` and `..`) into a caller buffer or a thread-local buffer. Neither checks the buffer length. The `_spill` variants take an extra `Vec`, compute an upper bound of the result from the input lengths, and grow the `Vec` and write there when the bound exceeds the buffer. <!-- robobun:evidence:begin --> --- **no test proof** · iteration 2 · Platform-specific test(s) that do not run on this machine. Deferring to CI, which covers all platforms: test/js/bun/shell/commands/rm.test.ts <!-- robobun:evidence:end -->
### Problem - GitHub closes only the first reference after a keyword, so "Fixes #1, #2" leaves #2 open. "Supersedes #3" links nothing, and no reference closes a pull request. - The last 1000 merged PRs name 274 such references. PR #32292 is open although merged #36135 says "Supersedes #32292". ### Fix - `.github/workflows/close-linked-issues.yml` runs on `pull_request_target` `closed` (a merge into the default branch of `oven-sh/bun`) and on `workflow_dispatch` with a PR number and `dry_run`. Everything is inline in one `actions/github-script` step, with no checkout. - Each open target is closed as `completed` with the comment "Closed as completed by #N." or "Superseded by #N.". Closed or missing targets, the PR itself and other repositories are skipped. - The parser has no regex. A closing keyword (close, fix, resolve, supersede, replace, any tense) must lead the reference, alone or in a list. A negated, hedged or noun keyword, or one whose subject is another reference, does not count ("may fix", "the rm fix #1", "#100 supersedes #1"). - Verified: `test/internal/close-linked-issues.test.ts` (333 cases) runs the YAML's script against fake `github`, `context` and `core`. Also the 1000-PR parse (Notes). ### Background - GitHub's own keywords are close, fix and resolve (-s, -ed). Each links one reference, and only a merge into the default branch closes it. - `pull_request_target` runs in the base repository with a write token, also for fork PRs. That is safe only when no PR-controlled code runs. Here the description is the only PR input, parsed as text. <details><summary>Notes</summary> A close through the API does not create the "closed this in #N" timeline link that GitHub makes for its own closes. The comment carries the PR number instead. How the parser was calibrated. I pulled the descriptions of the last 1000 merged PRs and listed every line with a keyword next to a reference. The keyword families, list shapes and reference forms in the script are the ones that appear there. A reference is `#1`, `owner/repo#1`, an issue or pull URL (bare or in `<>`), or a markdown link. Four lines would have been wrong with a plain keyword-then-reference rule, and each led to a rule: - "the open `rm` fix #37521" (#38379): "fix" as a noun. Base forms (fix, close, resolve, supersede, replace) count only at the start of a sentence or line, or after will, should, does, and, and a few similar words. "to" is not one of them ("unable to fix #1", "how to fix #1"). - "May also fix #12318 / #10046, untested" (#38242): hedged. may, might, could, would, partially and the negations disqualify the keyword, looking past adverbs such as "also". - "Supersedes the closed #26040" (#36289) and "a comment on closed #35351" (#35365): "closed" as an adjective. A determiner or preposition before the keyword disqualifies it. - "supersedes #33130's optimisation" (#35843): a number that continues into a word is not a reference. Review added: a reference before the keyword is the subject ("#100 supersedes #1"), also through "which" or "that" ("reverts #100, which fixed #1") and across a removed span ("#100 ~~also~~ fixes #1"). A hedge two words before the keyword disqualifies it ("hopefully this fixes #1", "could this fix #1?"). A clause that starts with if, when, once, until or unless is not a statement. The tokenizer keeps a line break as a token so that "Fixes #1" on one line and "Fixes #2" on the next stay two statements. Code spans, fences, indented code, blockquotes, HTML comments and strikethrough are skipped. The block stripping follows CommonMark for fences (also inside a blockquote), indented code, blockquotes with lazy continuation, setext underlines and HTML comments, and GFM for `~~` flanking. Result over the 1000 descriptions: 274 distinct references in 135 PRs. I checked the current state of all of them through GraphQL. All but one are closed (202 issues completed, 5 duplicates, 66 pull requests). The one open target is PR #32292, superseded by merged #36135. No open target is a false positive. Every review change kept this result. Patterns that are deliberately not handled: a bulleted list under "Closes:" on its own line (not seen in the sample), references separated by whitespace only ("#1 #2"), "fix for #1", and GH-1 style references. A `?` after the list is not treated as a question. The block parser tracks no list containers, so a second paragraph of a list item indented by four spaces is read as an indented code block and skipped. A removed span or inline comment reads as one word, so "Fixes <!-- n --> #1" finds nothing. The test suite covers: the phrases above, stopping at the right place in real sentences, CRLF descriptions, URLs with fragments or a `/files` suffix, case-insensitive `Owner/Repo#1`, the fake API where a lookup, an update or a comment fails, the `dry_run` input, an invalid `pr_number` input, an unmerged PR, a PR merged into a non-default branch, the merge event body against a later edit, and a description with no closing statement. The first revision of this PR checked out the repository and ran `scripts/close-linked-issues.ts`. Jarred asked for no checkout and no script file, so the script moved inline into the workflow and the test now reads it out of the YAML. </details> <!-- robobun:evidence:begin --> --- **[stamp-90s]** gate passed · iteration 9 · 2 files touched <details><summary>passes on PR (with fix)</summary> ```console Test-only change. Debug/ASAN (expected pass): $ bun bd test 'test/internal/close-linked-issues.test.ts' $ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test test/internal/close-linked-issues.test.ts bun test v1.4.1 (4448a2e) test/internal/close-linked-issues.test.ts: (pass) finds "Fixes #39852" [176.21ms] (pass) finds "Closes #31772. Fixes #31771." [22.28ms] (pass) finds "- Fixes #39930" [12.28ms] (pass) finds "Fixes: #30429" [10.46ms] (pass) finds "FIXES #1" [7.86ms] (pass) finds "(Fixes #1)" [8.97ms] (pass) finds "**Fixes #1**" [10.20ms] (pass) finds "__Fixes #1__" [9.83ms] (pass) finds "_Fixes #1_" [11.25ms] (pass) finds "Fixes **#1**" [9.72ms] (pass) finds "**Fixes** #1" [7.13ms] (pass) finds "**Fixes:** #1" [8.11ms] (pass) finds "Fixes #1 and **#2**" [11.47ms] (pass) finds "Fixes **#1**, **#2**" [9.13ms] (pass) finds "## Why (fixes #13771, closes #30543)" [16.08ms] (pass) finds "Closes #11418" [19.46ms] (pass) finds "Resolves #1. Resolved #2. Resolve #3." [12.09ms] (pass) finds "Fixes #34055, #30327, #24394, #20816, #32403, #11898, #10056." [17.11ms] (pass) finds "Fixes #18192 and #31675 as a consequence" [10.45ms] (pass) finds "Fixes #1, #2, and #3" [10.96ms] (pass) finds "Fixes #1 & #2" [7.63ms] (pass) finds "Closes #33280, Closes #32864 and Closes #29696 (the timer in #32949 is orthogonal)" [20.29ms] (pass) finds "Closes #33182 and #32947 on top of current main (which already has #36304 for catalogs)." [16.12ms] (pass) finds "Fixes #1,\n#2" [7.76ms] (pass) finds "Fixes #1, #2,\nand #3" [9.27ms] (pass) finds "Fixes #1\nand #2" [8.57ms] (pass) finds "Fixes #1\n& #2" [6.80ms] (pass) finds "Fixes #1 and\n#2" [7.31ms] (pass) finds "Supersedes #39908 (same change, moved from a fork branch)" [13.21ms] (pass) finds "Supersedes #38778 and #38391. Carries the entry point arm of #35053." [14.43ms] (pass) finds "Supersedes #39193 and keeps its three tests." [11.48ms] (pass) finds "This supersedes #33306 and #32803. Their tests are kept here." [13.73ms] (pass) finds "- This replaces #33793. Its ... (truncated) Exit: 0 ``` </details> <details><summary>diff hotspot</summary> ``` .github/workflows/close-linked-issues.yml | 950 ++++++++++++++++++++++++++++++ test/internal/close-linked-issues.test.ts | 598 +++++++++++++++++++ 2 files changed, 1548 insertions(+) ``` </details> **gate history** · 29 passed · 0 rejected · iteration 9 <details><summary>evidence per changed file</summary> ``` file reads edits tests .github/workflows/close-linked-issues.yml 6 12 0 test/internal/close-linked-issues.test.ts 3 11 0 ``` </details> <!-- robobun:evidence:end -->
Reproduction
The process aborts (exit 134). Expected:
rm: aaaa...: File name too long, exit code 1, and the script keeps running. Same crash for an absolute operand longer than 1024 bytes, and for a relative operand of roughly 4096 bytes or more (range end index N out of range for slice of length 4095, one buffer earlier).Cause
Before scheduling anything,
rmchecks that no operand resolves to the root (src/runtime/shell/builtin/rm.rs,ParseOptsstate). For each operand it callsresolve_path::join(cwd, operand)and thenresolve_path::normalize_string(resolved). Both write into fixed-size thread-local scratch buffers insrc/paths/resolve_path.rs(JOIN_BUF, 4096 bytes, andPARSER_BUFFER, 1024 bytes on every platform) with plain slice indexing, so an operand that does not fit panics. Operands come straight from the user, so there is no bound on their length; the shell cwd itself is already bounded to 4 KiB bycd.Fix
The check now joins through
join_spill(the existing helper that falls back to a caller-ownedVecwhen the thread-local buffer is too small, asBun.Globandfs.readdiralready do) and normalizes into aVecsized to the input vianormalize_string_buf. The logic of the check is unchanged, only the buffers are.Skipping the check for over-long operands would have been simpler but is not safe: a long
../../..chain that joins back down to/is still well underPATH_MAX, so the kernel would happily act on it. Running the check for every length keepsrmrefusing it (covered by theupToRootcase below), and operands that really are too long fall through tounlinkat, which reportsENAMETOOLONGthrough the normal per-operand error path; the other operands of the same invocation are still processed.Verification
New case in
test/js/bun/shell/commands/rm.test.tsrunsrmin a child process with a 1100-byte relative operand, a 1100-byte absolute operand, an 8192-byte operand (past the join buffer as well), a long operand next to a normal one that must still be removed, and (POSIX) a 6000-byte../chain that must still be refused with"/" may not be removed.USE_SYSTEM_BUN=1 bun test test/js/bun/shell/commands/rm.test.ts -t "operands longer": fails, the child aborts with the panic above.bun bd test test/js/bun/shell/commands/rm.test.ts: 8 pass.The same unbounded scratch-buffer pattern in the
mv,mkdirandtouchbuiltins, and the separate question of this check also refusing top-level paths like/app, are tracked separately; this PR only makes the existing check safe for any operand length.